package com.kuang.demo.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.kuang.demo.bean.BaseRespVo;
import com.kuang.demo.bean.GoodsBean.GoodsBO.CatAndBrandBO;
import com.kuang.demo.bean.GoodsBean.GoodsBO.GoodsAddList;
import com.kuang.demo.bean.GoodsBean.GoodsVO.GoodsListVO;
import com.kuang.demo.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/goods")
public class GoodsController {
    ObjectMapper mapper=new ObjectMapper();
    /**
     * GOODS LIST
     */
    @Autowired
    GoodsService goodsService;
    @GetMapping("list")
    public GoodsListVO goodsList(int page,int limit,String sort,String order){
        GoodsListVO goodsListVO = new GoodsListVO();
        goodsListVO=goodsService.goodsList(goodsListVO,page,limit,sort,order);
        return goodsListVO;
    }

    /**
     *
     * 添加商品的类别和标签
     */
    @GetMapping("catAndBrand")
    public CatAndBrandBO catAndBrand(){
        CatAndBrandBO catAndBrandBO = new CatAndBrandBO();
        catAndBrandBO=goodsService.catAndBrand(catAndBrandBO);
        return catAndBrandBO;
    }
    @PostMapping("create")
    public BaseRespVo addGoods(@RequestBody GoodsAddList goodsAddList){
        goodsService.addGoods(goodsAddList);
        return BaseRespVo.ok();
    }
}
